package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyLike;
import cn.wolfcode.trip.base.mapper.StrategyLikeMapper;
import cn.wolfcode.trip.base.service.IStrategyLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 给攻略点赞的service
 */
@Service
public class StrategyLikeServiceImpl implements IStrategyLikeService {

    @Autowired
    private StrategyLikeMapper strategyLikeMapper;

    /**
     * 点赞保存
     * @param strategyLike
     */
    @Override
    public void save(StrategyLike strategyLike) {
        strategyLikeMapper.insert(strategyLike);
    }

    /**
     * 点赞取消
     * @param strategyLike
     */
    @Override
    public void updateStatus(StrategyLike strategyLike) {
        strategyLikeMapper.updateStatus(strategyLike);
    }

    /**
     * 统计某条大攻略被点赞的次数
     * @param strategyId
     * @return
     */
    @Override
    public int getStrategyLikeCountByStrateId(Long strategyId) {
        Integer num = strategyLikeMapper.countNumByStrategyId(strategyId);
        if (num==null){
            return 0;
        }
        return num;
    }



    /**
     * 判断当前用户是否对该大攻略点了赞
     * @param strategyLike
     * @return
     */
    @Override
    public Integer getStatusByLikerId(StrategyLike strategyLike) {
        Integer flag = strategyLikeMapper.getStatusByLikerId(strategyLike);
        return flag;
    }
}
